<?php
namespace Manager\Controller;
use Think\Page;
/**
* ==============================================
* URL：http://www.liuhuanhui.cn
* ==============================================
* @date：2014-11-5
* @time：下午12:03:35
* @author：liuhuanhui
* @encoding：UTF-8
*/
class RemoveController extends  AuthController//回收站
{
	
	/**
	 *回收站
	 */
	function index()
	{
		if(I('key')!=null)
			$where['title']=array('like','%'.I('key').'%');
		if(!empty($_POST['sortId'])&&I('sortId')>=0)
			$where['sortId']=I('sortId');
		//分页获取数据
		$blog=D('BlogsView');
		$where['state']=array('eq','remove');
		$page=new Page($blog->where($where)->count(),10);
		$this->blogs=D('BlogsView')->where($where)->limit($page->firstRow,$page->listRows)->select();
		$this->pageShow=$page->show();
		//获取文章分类
		$this->sorts=M('sorts')->select();
		$this->display();
	}
	/**
	 *还原
	 */
	function recovert()
	{
		if(I('id'))
		{
            	$data=array(
					id=>I('id'),
					state=>'public',
			);
			if(M('blogs')->save($data))
			{
				$this->success("文章已经恢复到列表 ,点击返回文章列表",U(index));
			}else
			{
				$this->error("从回收站还原失败！");
			}
		}
	}
	/**
	 * 批量还原
	 */
	function recoverts()
	{
		
		$arr=join($_POST['selectIDS'], ',');
		$where['id']=array('in',$arr);
		if(M('blogs')->where($where)->setField('state','public'))
		{
			$this->success("批量还原成功！");
		}else
		{
			$this->error("批量还原失败!");
		}
	}

}